home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 102 / examples / getenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-25  |  1.3 KB  |  45 lines

  1. #include <basepage.h>
  2. /* As supplied in MAST-DOM-DEC'86
  3.  
  4. GETENV.C
  5.  
  6.     Keywords: ENVIRONMENT VARIABLE SHELL MARK WILLIAMS DOS C-SHELL GETENV
  7.     
  8.     
  9.             getenv is a small C routine that solves the incompatibility
  10.     problems between Mark Williams' and David Beckemeyer's environment block
  11.     formats. Compile it into your program and it will be used instead of the
  12.     library function. Arguments and return values are the same.
  13.  
  14.                                                                              */
  15.  
  16. char *getenv(S)  char *S;
  17. {
  18.         char *T, *U;
  19.         BASEPAGE *P;
  20.         P=BP;
  21.         T=(char *)(P->p_env);
  22.         while ((*T)!=0)
  23.         {
  24.                 U=S;
  25.                 while((*T)==(*U))
  26.                 {
  27.                           T++;
  28.                           U++;
  29.                 }
  30.                 if ((*T)=='='&&(*U)==0)
  31.                 {
  32.                           if (*(++T)==0)
  33.                           T++;
  34.                           return T;
  35.                 }
  36.                 if ((*T)!=0)
  37.                 {
  38.                           while ((*(T++))!=0);
  39.                 }
  40.                 else
  41.                 T++;
  42.          }
  43.          return NULL;
  44. }                                             
  45.